﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <map>
#include <vector>
#include <string>
#include <QString>
#include <QCloseEvent>
#include <QStandardItemModel>
#include "json.hpp"
#include "video_widget.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
private slots:
     //加入房间
    void on_Join_clicked();
    void on_Join_2_clicked();

    void on_comboMics_currentIndexChanged(int index);

    void on_comboSpeakers_currentIndexChanged(int index);

    void on_comboCamera_currentIndexChanged(int index);

    void on_loggerButton_clicked();

    void on_roomIds_currentIndexChanged(int index);

    void on_audioCtrlButton_clicked();
    void on_videoCtrlButton_clicked(bool checked);
    void on_screenShareBtn_clicked();
    void on_comboResolution_currentIndexChanged(int index);

    void on_networkSensitivity_currentIndexChanged(int index);

    void on_btnStartRecord_clicked();

    void on_btnStopRecord_clicked();

    void on_btnLnkChk_clicked();

    void on_btnFrame_clicked();

    void on_comboNAP_currentIndexChanged(int index);
    void on_btnBitrateSet_clicked();

public:
    //设置窗口可见
    void SetWidgetVisible(QWidget *w,bool visible);
    //设置初始化UI状态
    void ResetUI();
    //处理用户离开
    void ProcessPeerLeave(std::string peerId);
private:
    void UpdateUI();
    //更新链路传输状态信息
    void updateLinkStatus(const nlohmann::json linkInfo);

    void mouseDoubleClickEvent(QMouseEvent*) override;
    //覆写closeEvent函数
    void closeEvent(QCloseEvent *) override;
    //事件过滤器
    bool eventFilter(QObject *obj, QEvent *event) override;
public:
    Ui::MainWindow *ui;

    void* m_handle;
    std::string _roomid;
    std::string _roomPasswd;
    std::string _memberId;
    std::string _nickName;
    std::string _dispServer;

    int _cameras=0;
    int _mics=0;
    int _speakers=0;
    int _suggestMic=-1;
    int _suggestSpeaker=-1;

    std::string dispServer = "https://119.3.238.51:3443";
    std::string avator_url="http://someone.jpg";
    int port = 3443;

    std::vector<int> _micsMap;
    std::vector<int>_speakersMap;
    std::vector<int>_camerasMap;
    GridManager* _gridManager;
    //媒体状体信息
    QStandardItemModel *_dataModel=NULL;

};

#endif // MAINWINDOW_H
